package example;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.rmi.RemoteException;

public class ForwardRequest extends Thread{
	//destination host
	Socket destinationHostSocket = null;
    /*PrintWriter out = null;
    BufferedReader in = null;*/
    ObjectInputStream in = null;
    ObjectOutputStream out = null;
    
    
    Socket destinationSocket;
    MixProtocol mp;
    
    String destinationHost = "";
    String requestStatement = "";  
    MixProtocol fromServer;//result from server
    //tra ve cho client    
    Socket clientSocket = null;
    PrintWriter outClient = null;
    BufferedReader inClient = null;
    String PARTICIPANT_CMD = "participant";
    private static final int timeout_length = 40000;
    protected int m_rate = 100;    
    
    public ForwardRequest() {
    	
    }
    public ForwardRequest(Socket destinationSocket,Socket cSocket,MixProtocol mp) {
    	this.destinationSocket = destinationSocket;
    	this.mp = mp;
    	this.clientSocket = cSocket;
    	//kiem tra socket
    }
    public void run() {
    	try {
    		out = new ObjectOutputStream(destinationSocket.getOutputStream());
    		in = new ObjectInputStream(destinationSocket.getInputStream());
    		if (mp != null) {
    	    	out.writeObject(mp);
    		}
    	}	
    	catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try{
			//if ((fromServer = in.readLine()) != null) {
			//if ((fromServer = (MixProtocol)in.readObject()) != null) {		
			//	System.out.println("forwardTo return result"+fromServer.type+" 3 = RESULT");
			//}
		}
		catch (Exception e) {
			System.out.println(e.getMessage());
		}
    }
}
